package com.senseu.utils;

import org.openqa.selenium.WebElement;

import java.lang.reflect.Proxy;

public class ElementWrapper {

    public static WebElement wrap(WebElement element,TapHelper tapHelper) {
        return (WebElement) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{WebElement.class},
                (proxy, method, args) -> {
                    if (method.getName().equals("click")) {
                        tapHelper.tap(element);
                        return null;
                    }
                    return method.invoke(element, args);
                }
        );
    }
}
